//
//  RankTableView.m
//  GameBaby
//
//  Created by keyZhang on 13-12-29.
//  Copyright (c) 2013年 keyZhang. All rights reserved.
//

#import "RankTableView.h"
#import "RankTableViewCell.h"
#import "GameCenterViewController.h"

@implementation RankTableView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/


#pragma mark -UITableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *identifier = @"homeCell";
    RankTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"RankTableViewCell" owner:self options:nil] lastObject];
    }
    cell.rankLabel.text = [NSString stringWithFormat:@"%d",indexPath.row + 1];
    if (indexPath.row < 3) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 25, 30, 30)];
        [cell.contentView addSubview:imgView];
        if (indexPath.row == 0) {
            cell.rankLabel.hidden = YES;
            imgView.image = [UIImage imageNamed:@"nav05.png"];
        }else if (indexPath.row == 1)
        {
            cell.rankLabel.hidden = YES;
            imgView.image = [UIImage imageNamed:@"navs_13.png"];
        }else if (indexPath.row == 2)
        {
            cell.rankLabel.hidden = YES;
            imgView.image = [UIImage imageNamed:@"nav_24.png"];
        }
        
    }
    
    cell.model = self.dataList[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    GameCenterViewController *gameCenterVC = [[GameCenterViewController alloc] init];
    gameCenterVC.gameXqUrl = [(HomeCellModel *)self.dataList[indexPath.row] url];
    [self.viewController.navigationController pushViewController:gameCenterVC animated:YES];
}

@end
